<?php

use think\migration\Migrator;
use think\migration\db\Column;
use Phinx\Db\Adapter\MysqlAdapter;

class XyAuthMenu extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('xy_auth_menu', ['engine' => 'InnoDB', 'collation' => 'utf8_general_ci', 'comment' => '' ,'id' => 'id' ,'primary_key' => ['id']]);
        $table->addColumn('namespace', 'string', ['limit' => 32,'null' => false,'default' => 'uiadmin','signed' => true,'comment' => '根命名空间',])
			->addColumn('module', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '所属模块',])
			->addColumn('title', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '名称',])
			->addColumn('icon', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '图标',])
			->addColumn('path', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '路由路径',])
			->addColumn('pmenu', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '父菜单',])
			->addColumn('sortnum', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '排序',])
			->addColumn('menu_layer', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '分层标记',])
			->addColumn('menu_type', 'integer', ['limit' => MysqlAdapter::INT_REGULAR,'null' => false,'default' => 0,'signed' => true,'comment' => '菜单类型1导航2按钮3仅接口',])
			->addColumn('route_type', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '路由类型',])
			->addColumn('api_prefix', 'string', ['limit' => 15,'null' => false,'default' => '','signed' => true,'comment' => '接口前缀, 一般为：v1',])
			->addColumn('api_suffix', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '接口路由参数后缀',])
			->addColumn('api_params', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '接口Query参数',])
			->addColumn('out_url', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => '外链地址或者远程组件地址',])
			->addColumn('is_dev', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '是否开发者模式才显示',])
			->addColumn('create_time', 'datetime', ['null' => true,'signed' => true,'comment' => '创建时间',])
			->addColumn('update_time', 'datetime', ['null' => true,'signed' => true,'comment' => '更新时间',])
			->addColumn('status', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '删除状态，0已禁用1正常',])
			->addColumn('tip', 'string', ['limit' => 255,'null' => false,'default' => '','signed' => true,'comment' => 'Tip',])
			->addColumn('api_method', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '接口请求方法',])
			->addColumn('is_hide', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '是否隐藏菜单',])
			->addColumn('doc', 'text', ['limit' => MysqlAdapter::TEXT_REGULAR,'null' => true,'signed' => true,'comment' => '接口文档',])
			->addColumn('api_ext', 'string', ['limit' => 32,'null' => false,'default' => '','signed' => true,'comment' => '接口虚拟后缀',])
			->addColumn('delete_time', 'boolean', ['null' => false,'default' => 0,'signed' => true,'comment' => '删除时间',])
			->addIndex(['id'], ['unique' => true,'name' => 'id'])
            ->create();
        
        // 后台菜单
        $data = array(
            [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "开发",
                "icon" => "xyicon-coding",
                "path" => "/developer",
                "pmenu" => "/_tab_system",
                "sortnum" => 99,
                "menu_layer" => "admin",
                "menu_type" => 0,
                "route_type" => "",
                "api_prefix" => "",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "一般是开发者采用得到的工具",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "系统",
                "icon" => "xyicon-settings",
                "path" => "/core",
                "pmenu" => "/_tab_system",
                "sortnum" => 1,
                "menu_layer" => "admin",
                "menu_type" => 0,
                "route_type" => "",
                "api_prefix" => "",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "核心系统相关功能",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "清空缓存",
                "icon" => "",
                "path" => "/core/index/cleanRuntime",
                "pmenu" => "/core",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 3,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "清空服务器端缓存",
                "api_method" => "DELETE",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "检查更新",
                "icon" => "",
                "path" => "/core/index/checkUpdate",
                "pmenu" => "/core",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 3,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "检查新版本",
                "api_method" => "GET",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "管理后台",
                "icon" => "",
                "path" => "/_root_admin",
                "pmenu" => "",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => -1,
                "route_type" => "",
                "api_prefix" => "",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "后台根节点",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "系统",
                "icon" => "xyicon-settings",
                "path" => "/_tab_system",
                "pmenu" => "/_root_admin",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => -1,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "系统TAB",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => "",
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "用户",
                "icon" => "xyicon-my-o",
                "path" => "/_tab_user",
                "pmenu" => "/_root_admin",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => -1,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "用户TAB",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => "",
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "内容",
                "icon" => "xyicon-plane-o",
                "path" => "/_tab_content",
                "pmenu" => "/_root_admin",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => -1,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "内容TAB",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => "",
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-core",
                "title" => "财务",
                "icon" => "md-card",
                "path" => "/_tab_money",
                "pmenu" => "/_root_admin",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => -1,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "财务TAB",
                "api_method" => "",
                "is_hide" => 0,
                "doc" => "",
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "菜单列表",
                "icon" => "",
                "path" => "/auth/menu/lists",
                "pmenu" => "/developer",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 3,
                "route_type" => "list",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "管理后台左侧的菜单导航",
                "api_method" => "GET",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "权限管理",
                "icon" => "",
                "path" => "/auth/role/trees",
                "pmenu" => "/core",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 1,
                "route_type" => "list",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "管理系统角色及权限",
                "api_method" => "GET",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "用户列表",
                "icon" => "",
                "path" => "/auth/user/lists",
                "pmenu" => "/core",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 1,
                "route_type" => "list",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "系统注册用户列表",
                "api_method" => "GET",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "修改用户",
                "icon" => "",
                "path" => "/auth/user/edit",
                "pmenu" => "/auth/user/lists",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "修改用户信息",
                "api_method" => "GET|PUT",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "删除用户",
                "icon" => "",
                "path" => "/auth/user/delete",
                "pmenu" => "/auth/user/lists",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "软删除用户",
                "api_method" => "DELETE",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "添加用户",
                "icon" => "",
                "path" => "/auth/user/add",
                "pmenu" => "/auth/user/lists",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "添加用户",
                "api_method" => "GET|POST",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "菜单管理",
                "icon" => "",
                "path" => "/auth/menu/trees",
                "pmenu" => "/developer",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 1,
                "route_type" => "list",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "管理系统后台左侧菜单",
                "api_method" => "GET",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "修改角色",
                "icon" => "",
                "path" => "/auth/role/edit",
                "pmenu" => "/auth/role/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "修改角色信息及权限",
                "api_method" => "GET|PUT",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "删除角色",
                "icon" => "",
                "path" => "/auth/role/delete",
                "pmenu" => "/auth/role/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "删除角色",
                "api_method" => "DELETE",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "添加角色",
                "icon" => "",
                "path" => "/auth/role/add",
                "pmenu" => "/auth/role/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "添加角色",
                "api_method" => "GET|POST",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "角色成员",
                "icon" => "",
                "path" => "/auth/user_role/lists",
                "pmenu" => "/auth/role/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "list",
                "api_prefix" => "v1",
                "api_suffix" => "/:name",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "管理角色成员",
                "api_method" => "GET",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "添加角色成员",
                "icon" => "",
                "path" => "/auth/user_role/add",
                "pmenu" => "/auth/user_role/lists",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "/:name",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "添加一个新角色成员",
                "api_method" => "GET|POST",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "删除角色成员",
                "icon" => "",
                "path" => "/auth/user_role/delete",
                "pmenu" => "/auth/user_role/lists",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "/:uid/:name",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "删除一个角色成员",
                "api_method" => "DELETE",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "添加菜单",
                "icon" => "",
                "path" => "/auth/menu/add",
                "pmenu" => "/auth/menu/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "添加后台菜单(接口)",
                "api_method" => "GET|POST",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "修改菜单",
                "icon" => "",
                "path" => "/auth/menu/edit",
                "pmenu" => "/auth/menu/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "form",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "修改后台菜单(接口)",
                "api_method" => "GET|PUT",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "删除菜单",
                "icon" => "",
                "path" => "/auth/menu/delete",
                "pmenu" => "/auth/menu/trees",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "删除后台菜单(接口)",
                "api_method" => "DELETE",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ],
                [
                "namespace" => "uiadmin",
                "module" => "uiadmin-auth",
                "title" => "用户详情",
                "icon" => "",
                "path" => "/auth/user/info",
                "pmenu" => "/auth/user/lists",
                "sortnum" => 0,
                "menu_layer" => "admin",
                "menu_type" => 2,
                "route_type" => "tab",
                "api_prefix" => "v1",
                "api_suffix" => "/:id",
                "api_params" => "",
                "out_url" => "",
                "is_dev" => 0,
                "create_time" => null,
                "update_time" => null,
                "status" => 1,
                "tip" => "添加用户",
                "api_method" => "GET|POST",
                "is_hide" => 0,
                "doc" => null,
                "api_ext" => "",
                "delete_time" => 0
                ]
        );

        $posts = $this->table('xy_auth_menu');
        $posts->insert($data)
                ->save();
    }
}
